<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Connecting to IBM databases</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.pdo-ibm.html">IBM (PDO)</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.pdo-informix.html">Informix (PDO)</a></div>
 <div class="up"><a href="ref.pdo-ibm.html">IBM (PDO)</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="ref.pdo-ibm.connection" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">PDO_IBM DSN</h1>
    <p class="verinfo">(PECL PDO_IBM &gt;= 0.9.0)</p><p class="refpurpose"><span class="refname">PDO_IBM DSN</span> &mdash; <span class="dc-title">Connecting to IBM databases</span></p>

   </div>

   <div class="refsect1 description" id="refsect1-ref.pdo-ibm.connection-description">
    <h3 class="title">说明</h3>
    <p class="para">
     The PDO_IBM Data Source Name (DSN) is based on the IBM CLI DSN. The major 
     components of the PDO_IBM DSN are: 
     <dl>

      
       <dt>
DSN prefix</dt>

       <dd>

        <p class="para">
        The DSN prefix is <strong class="userinput"><code>ibm:</code></strong>.
        </p>
       </dd>

      
      
       <dt>
DSN</dt>

       <dd>

        <p class="para">
         The DSN can be any of the following:
         <ul class="itemizedlist">
          <li class="listitem">
           <p class="para">
            a) Data source setup using <var class="filename">db2cli.ini</var> 
            or <var class="filename">odbc.ini</var>
           </p>
          </li>
          <li class="listitem">
           <p class="para">
            b) Catalogued database name i.e. database alias in the DB2 client 
            catalog
           </p>
          </li>
          <li class="listitem">
           <p class="para">
             c) Complete connection string in the following format: 
             <code class="code">DRIVER={IBM DB2 ODBC DRIVER};DATABASE=<em><code class="parameter">database</code></em>;HOSTNAME=<em><code class="parameter">hostname</code></em>;PORT=<em><code class="parameter">port</code></em>;PROTOCOL=TCPIP;UID=<em><code class="parameter">username</code></em>;PWD=<em><code class="parameter">password</code></em>;</code> 
             where the parameters represent the following values:
             <dl>

              
               <dt>
<em><code class="parameter">database</code></em></dt>

               <dd>

                <p class="para">
                 The name of the database.
                </p>
               </dd>

              
              
               <dt>
<em><code class="parameter">hostname</code></em></dt>

               <dd>

                <p class="para">
                 The hostname or IP address of the database server.
                </p>
               </dd>

              
              
               <dt>
<em><code class="parameter">port</code></em></dt>

               <dd>

                <p class="para">
                 The TCP/IP port on which the database is listening for
                 requests.
                </p>
               </dd>

              
              
               <dt>
<em><code class="parameter">username</code></em></dt>

               <dd>

                <p class="para">
                 The username with which you are connecting to the
                 database.
                </p>
               </dd>

              
              
               <dt>
<em><code class="parameter">password</code></em></dt>

               <dd>

                <p class="para">
                 The password with which you are connecting to the database.
                </p>
               </dd>

              
             </dl>

            </p>
           </li>
          </ul>
        </p>
       </dd>

      
     </dl>

    </p>
   </div>

   <div class="refsect1 examples" id="refsect1-ref.pdo-ibm.connection-examples">
    <h3 class="title">范例</h3>
    <p class="para">
     <div class="example" id="example-947">
      <p><strong>Example #1 PDO_IBM DSN example using <var class="filename">db2cli.ini</var></strong></p>
      <div class="example-contents"><p>
       The following example shows a PDO_IBM DSN for connecting to an DB2 
       database cataloged as DB2_9 in <var class="filename">db2cli.ini</var>:
       <div class="example-contents"><div class="cdata"><pre>
$db = new PDO(&quot;ibm:DSN=DB2_9&quot;, &quot;&quot;, &quot;&quot;);

[DB2_9]
Database=testdb
Protocol=tcpip
Hostname=11.22.33.444
Servicename=56789
</pre></div></div>

      </p></div>
     </div>
     <div class="example" id="example-948">
      <p><strong>Example #2 PDO_IBM DSN example using a connection string</strong></p>
      <div class="example-contents"><p>
       The following example shows a PDO_IBM DSN for connecting to an DB2 
       database named <strong class="userinput"><code>testdb</code></strong> using the DB2 CLI 
       connection string syntax. 
       <div class="example-contents"><div class="cdata"><pre>
$db = new PDO(&quot;ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=testdb;&quot; .
  &quot;HOSTNAME=11.22.33.444;PORT=56789;PROTOCOL=TCPIP;&quot;, &quot;testuser&quot;, &quot;tespass&quot;);
</pre></div>
       </div>

      </p></div>
     </div>
    
    </p>
   </div>

  </div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="ref.pdo-ibm.html">IBM (PDO)</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="ref.pdo-informix.html">Informix (PDO)</a></div>
 <div class="up"><a href="ref.pdo-ibm.html">IBM (PDO)</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
